/*
 * TickBar.java
 *
 * Created on September 19, 2008, 11:57 PM
 */

package openrule;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;

/**
 *
 * @author  leadiv
 */
public class TickBar extends javax.swing.JPanel implements Drawable {

    /** Creates new form TickBar */
    public TickBar() {
        this.smallTickHeight = 10;
        this.mediumTickHeight = 15;
        this.largeTickHeight = 20;
        
        initComponents();
    }

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        draw(g);
    }
    
    public void draw(Graphics g) {
        Dimension d = new Dimension();
        int i = 0;
        int spacegap = 2;
        int textOffset;

        this.getSize(d);
        for(;i < d.width; i+=spacegap)
        {
            switch(i % 20)
            {
                case 0:
                    g.drawLine(i, d.height, i, d.height - this.largeTickHeight);
                    g.setFont(new Font("SansSerif", Font.PLAIN, 9));
                    textOffset = ((int)Math.log10(i) + 1) * 2;
                    textOffset = textOffset != 2 ? textOffset : 0;
                    g.drawString(Integer.toString(i), i - textOffset, d.height - this.largeTickHeight - 2);
                break;
                
                case 10:
                    g.drawLine(i, d.height, i, d.height - this.mediumTickHeight);
                break;
                
                default:
                    g.drawLine(i, d.height, i, d.height - this.smallTickHeight);
            }
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setLayout(null);
    }// </editor-fold>//GEN-END:initComponents

   protected int smallTickHeight, largeTickHeight, mediumTickHeight;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
